<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="生产阶别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['produceGrade', validatorRules.produceGrade]" :trigger-change="true" dictCode="produce_grade" placeholder="请选择生产阶别"/>
        </a-form-item>
        <a-form-item label="机种名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['machineName']" placeholder="请输入机种名称"></a-input>
        </a-form-item>
        <a-form-item label="生产线别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['produceLinesort', validatorRules.produceLinesort]" placeholder="请输入生产线别"></a-input>
        </a-form-item>
        <a-form-item label="机种规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['machineGague']" placeholder="请输入机种规格"></a-input>
        </a-form-item>
        <a-form-item label="机种" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['machineSort', validatorRules.machineSort]" placeholder="请输入机种"></a-input>
        </a-form-item>
        <a-form-item label="标准工时(S)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['standardWorktime', validatorRules.standardWorktime]" placeholder="请输入标准工时(S)"></a-input>
        </a-form-item>
        <a-form-item label="加工面别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['processFace', validatorRules.processFace]" :trigger-change="true" dictCode="process_face" placeholder="请选择加工面别"/>
        </a-form-item>
        <a-form-item label="换线时间(Min)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['changeLinetime', validatorRules.changeLinetime]" placeholder="请输入换线时间(Min)"></a-input>
        </a-form-item>
        <a-form-item label="生产工艺" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['produceCraft']" placeholder="请输入生产工艺"></a-input>
        </a-form-item>
        <a-form-item label="排程计算标志" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['eissionToken']" :trigger-change="true" dictCode="yn" placeholder="请选择排程计算标志"/>
        </a-form-item>
        <a-form-item label="SMT轨道" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['smtTrack', validatorRules.smtTrack]" :trigger-change="true" dictCode="smt_track" placeholder="请选择SMT轨道"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"


  export default {
    name: "MesChiefdataStandardworktimeModal",
    components: { 
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          produceGrade: {
            rules: [
              { required: true, message: '请输入生产阶别!'},
            ]
          },
          produceLinesort: {
            rules: [
              { required: true, message: '请输入生产线别!'},
            ]
          },
          machineSort: {
            rules: [
              { required: true, message: '请输入机种!'},
            ]
          },
          standardWorktime: {
            rules: [
              { required: true, message: '请输入标准工时(S)!'},
            ]
          },
          processFace: {
            rules: [
              { required: true, message: '请输入加工面别!'},
            ]
          },
          changeLinetime: {
            rules: [
              { required: true, message: '请输入换线时间(Min)!'},
            ]
          },
          smtTrack: {
            rules: [
              { required: true, message: '请输入SMT轨道!'},
            ]
          },
        },
        url: {
          add: "/chiefdata/mesChiefdataStandardworktime/add",
          edit: "/chiefdata/mesChiefdataStandardworktime/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'produceGrade','machineName','produceLinesort','machineGague','machineSort','standardWorktime','processFace','changeLinetime','produceCraft','eissionToken','smtTrack'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'produceGrade','machineName','produceLinesort','machineGague','machineSort','standardWorktime','processFace','changeLinetime','produceCraft','eissionToken','smtTrack'))
      },

      
    }
  }
</script>